/*
 * @Author: 康为 18037890117@163.com
 * @Date: 2023-07-06 13:19:10
 * @LastEditors: 康为 18037890117@163.com
 * @LastEditTime: 2023-07-19 15:48:42
 * @FilePath: /umi-max/src/framework/Card/index.tsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import * as React from 'react';
import classNames from 'classnames';
import configs from '@/modules/mapping';
import CardHead from './CardHead';
import CardBody from './CardBody';
import styles from './index.less';
import { isNil } from 'lodash';

export interface CardFrameProps {
  id?: string;
  style?: React.CSSProperties;
  width?: number;
  cardType: string;
  echartsLoading?: boolean;
  echartsData?: Record<string, any>;
  title: string;
  loading?: string;
  cardClassName?: string;
  zoomShow?: string;
  settings?: Record<string, any>;
  hasPermission?: boolean;
}

function CardFrame(props: CardFrameProps) {
  const {
    id,
    title,
    style,
    width,
    cardType,
    loading,
    settings,
    hasPermission,
    ...otherProps
  } = props;
  const {
    renderCustom,
    hideHeader,
    cardClassName,
    cardHeadClassName,
    cardBodyClassName,
  } = configs[cardType];
  const withSpaceSize = isNil(configs[cardType].withSpaceSize)
    ? {}
    : { margin: configs[cardType].withSpaceSize };
  return (
    <div
      id={id}
      data-type={cardType}
      className={classNames(styles.cardWrapper, cardClassName)}
      style={{ ...withSpaceSize, ...style, width }}
    >
      {!hideHeader && (
        <CardHead
          title={title}
          cardHeadClassName={cardHeadClassName}
          renderCustom={renderCustom}
          settings={settings}
          hasPermission={hasPermission}
        />
      )}
      <CardBody
        loading={loading}
        hideHeader={hideHeader}
        cardType={cardType}
        cardBodyClassName={cardBodyClassName}
        hasPermission={hasPermission}
        settings={settings}
        {...otherProps}
      />
    </div>
  );
}

export default CardFrame;
